<cd-loading-panel *ngIf="editing && loading && !error"
                  i18n>Loading bucket data...</cd-loading-panel>
<cd-error-panel *ngIf="editing && error"
                (backAction)="goToListView()"
                i18n>The bucket data could not be loaded.</cd-error-panel>

<div class="col-sm-12 col-lg-6"
     *ngIf="!loading && !error">
  <form name="bucketForm"
        class="form-horizontal"
        #frm="ngForm"
        [formGroup]="bucketForm"
        novalidate>
    <div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="panel-title"
            i18n>{editing, select, 1 {Edit} other {Add}} bucket</h3>
      </div>
      <div class="panel-body">

        <!-- Id -->
        <div class="form-group"
             *ngIf="editing">
          <label i18n
                 class="col-sm-3 control-label"
                 for="id">Id</label>
          <div class="col-sm-9">
            <input id="id"
                   name="id"
                   class="form-control"
                   type="text"
                   formControlName="id"
                   readonly>
          </div>
        </div>

        <!-- Name -->
        <div class="form-group"
             [ngClass]="{'has-error': bucketForm.showError('bid', frm)}">
          <label class="control-label col-sm-3"
                 for="bid">
            <ng-container i18n>Name</ng-container>
            <span class="required"
                  *ngIf="!editing"></span>
          </label>
          <div class="col-sm-9">
            <input id="bid"
                   name="bid"
                   class="form-control"
                   type="text"
                   i18n-placeholder
                   placeholder="Name..."
                   formControlName="bid"
                   [readonly]="editing"
                   autofocus>
            <span class="help-block"
                  *ngIf="bucketForm.showError('bid', frm, 'required')"
                  i18n>This field is required.</span>
            <span class="help-block"
                  *ngIf="bucketForm.showError('bid', frm, 'bucketNameInvalid')"
                  i18n>The value is not valid.</span>
            <span class="help-block"
                  *ngIf="bucketForm.showError('bid', frm, 'bucketNameExists')"
                  i18n>The chosen name is already in use.</span>
          </div>
        </div>

        <!-- Owner -->
        <div class="form-group"
             [ngClass]="{'has-error': bucketForm.showError('owner', frm)}">
          <label class="control-label col-sm-3"
                 for="owner">
            <ng-container i18n>Owner</ng-container>
            <span class="required"></span>
          </label>
          <div class="col-sm-9">
            <select id="owner"
                    name="owner"
                    class="form-control"
                    formControlName="owner">
              <option i18n
                      *ngIf="owners === null"
                      [ngValue]="null">Loading...</option>
              <option i18n
                      *ngIf="owners !== null"
                      [ngValue]="null">-- Select a user --</option>
              <option *ngFor="let owner of owners"
                      [value]="owner">{{ owner }}</option>
            </select>
            <span class="help-block"
                  *ngIf="bucketForm.showError('owner', frm, 'required')"
                  i18n>This field is required.</span>
          </div>
        </div>

      </div>
      <div class="panel-footer">
        <div class="button-group text-right">
          <cd-submit-button type="button"
                            (submitAction)="submit()"
                            [form]="bucketForm">
            <ng-container i18n>{editing, select, 1 {Update} other {Add}}</ng-container>
          </cd-submit-button>
          <button i18n
                  type="button"
                  class="btn btn-sm btn-default"
                  routerLink="/rgw/bucket">Back</button>
        </div>
      </div>
    </div>
  </form>
</div>
